Struts2 组合框示例 您所在的位置:网站首页 combobox jsp Struts2 组合框示例

Struts2 组合框示例

2023-10-24 14:50| 来源: 网络整理| 查看: 265

下载它– Struts-ComboBox-Example.zip

在Struts 2中, 标记基本上是一个与单行文本框组合在一起的下拉列表 ,允许用户在文本框中直接输入值或从下拉列表中选择值,所选的值将自动填充到文本框中。

如果您在下拉列表和组合框列表之间感到困惑,请从Wiki阅读组合框定义 。

结果如下HTML代码…

What's your favor fruit: function autoPopulate_resultAction_yourFruits(targetElement) { if (targetElement.options[targetElement.selectedIndex].value == '-1') { return; } targetElement.form.elements['yourFruits'].value= targetElement.options[targetElement.selectedIndex].value; } --- Select --- Apple Banana Orange Watermelon

标记将生成一个输入文本框,其下拉列表具有“ onChange() ”行为,以调用生成JavaScript函数以将下拉列表中的选定值自动填充到生成的文本框中。

要创建下拉列表,您应该改用标记。

Struts 2 示例

一个完整的Struts 2示例,通过展示了组合框的用法

1.行动

动作类,用于生成并保留选定的组合框选项。 ComboBoxAction.java

package com.mkyong.common.action; import java.util.ArrayList; import java.util.List; import com.opensymphony.xwork2.ActionSupport; public class ComboBoxAction extends ActionSupport{ private List fruits; private String yourFruits; private String yourMonth; public String getYourMonth() { return yourMonth; } public void setYourMonth(String yourMonth) { this.yourMonth = yourMonth; } public List getFruits() { return fruits; } public void setFruits(List fruits) { this.fruits = fruits; } public String getYourFruits() { return yourFruits; } public void setYourFruits(String yourFruits) { this.yourFruits = yourFruits; } public ComboBoxAction(){ fruits = new ArrayList(); fruits.add("Apple"); fruits.add("Banana"); fruits.add("Orange"); fruits.add("Watermelon"); } public String execute() { return SUCCESS; } public String display() { return NONE; } } 2.结果页面

通过“ ”标记渲染组合框,并通过Java列表和OGNL列表填充选择选项

combobox.jsp

Struts 2 ;s:combobox; example

result.jsp

Struts 2 ;s:combobox; example Favor fruit : Selected month : 3. struts.xml

链接在一起〜

pages/combobox.jsp pages/result.jsp 5.演示

http:// localhost:8080 / Struts2Example / comboBoxAction.action

Struts 2 combo box example

http:// localhost:8080 / Struts2Example / resultAction.action

Struts 2 combo box example 参考 Struts 2组合框文档 Wiki组合框定义 标签: 下拉式 struts2

翻译自: https://mkyong.com/struts2/struts-2-scombobox-combo-box-example/



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有